package com.java.mall_imooc.common.utils;

import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * 获取HttpServletRequest和HttpServletResponse的工具类
 * @author jiangli
 * @since 2020-03-15 21:5
 */
public class ContextHolderUtils {

    public static HttpServletRequest getRequest() {
		return ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();

    }

    public static HttpServletResponse getResponse() {
		return ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getResponse();

    }

    public static HttpSession getSession() {
		return getRequest().getSession();
    }

}